#include "SelectServer.h"
#include "Error.h"
#include <memory>
#include <string>
#include <cstdlib>

using namespace std;
using namespace select_server;

static void usage(std::string proc) {
    std::cerr << "Usage:\n\t" << proc << " port" << "\n\n";
}

string appendString(const string& request) {
    string ret;
    for (int i = request.size() - 2; i >= 0; --i) {
        ret += request[i];
    }
    ret += "\n";
    return ret;
}

// ./SelectServer 18989
int main(int argc, char** argv) {
    if (argc != 2) {
        usage(argv[0]);
        exit(USAGE_ERR);
    }

    unique_ptr<SelectServer> select_server(new SelectServer(appendString, static_cast<uint16_t>(atoi(argv[1]))));

    select_server->initServer();
    select_server->run();

    return 0;
}
